const Koa = require('koa')
const app = new Koa()
const userRouter = require('./router/user.js')
const noteRouter = require('./router/note.js')
const cors = require('@koa/cors')
const {bodyParser} = require('@koa/bodyparser')

app.use(cors())
app.use(bodyParser())
//1. 被app.use的函数，一定拥有参数ctx
//2. userRouter.routes() 路由中间件
app.use(userRouter.routes(),userRouter.allowedMethods())
app.use(noteRouter.routes(),noteRouter.allowedMethods())
// app.use(async (ctx) => {
//     console.log(ctx)
//     if (ctx.path === '/home') {
//         ctx.body = 'hello Koa'
//     }
//     else {
//         ctx.body = '404 Not Found'
//     }
// })

app.listen(3000, () => {
    console.log('server start at http://localhost:3000')
})